home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------------------
- //
- // TIMERTST.CPP
- //
- // Test Application which uses the OTimer class. Note: This requires
- // Borland C++ (it uses the Object Windows Library).
- //
- //--------------------------------------------------------------------------
-
- #include "otimer.h"
- #ifndef __OWL_H
- #include <owl.h>
- #endif
- #ifndef __WINDOW_H
- #include <window.h>
- #endif
-
-
- //--------------------------------------------------------------------------
- //
- // Timer test class
- //
- //--------------------------------------------------------------------------
- class TestTimer : public OTimer {
- private:
- int wCount;
- HWND hwndOwner;
- RECT rDisplay;
-
- virtual void timerHit(DWORD dwTime);
- public:
- TestTimer(HWND hwnd, RECT &r, UINT mSec)
- : hwndOwner(hwnd), rDisplay(r)
- {
- wCount = 0;
- go(mSec);
- }
-
- void draw(HDC drawDC);
-
- };
-
-
-
- //--------------------------------------------------------------------------
- //
- // TestTimer :: timerHit
- //
- // Respond to timer callback
- //
- //--------------------------------------------------------------------------
- void TestTimer::timerHit(DWORD)
- {
- ++wCount;
-
- HDC wndDC = GetDC(hwndOwner);
-
- if(wndDC) {
- draw(wndDC);
- ReleaseDC(hwndOwner, wndDC);
- };
- }
-
- //--------------------------------------------------------------------------
- //
- // Perform actual drawing
- //
- //--------------------------------------------------------------------------
- void TestTimer::draw(HDC wndDC)
- {
- // this drawing (we hope!) is OK
- char szBuffer[20];
- RECT rText;
-
- HGDIOBJ hOldFont = SelectObject(wndDC, GetStockObject(SYSTEM_FONT));
- wsprintf(szBuffer, "%5d", wCount);
- ExtTextOut(wndDC, rDisplay.left, rDisplay.top, ETO_OPAQUE,
- &rDisplay, szBuffer, lstrlen(szBuffer), NULL);
-
- SelectObject(wndDC, hOldFont);
- }
-
-
- //--------------------------------------------------------------------------
- //
- // TTimerWindow
- //
- //--------------------------------------------------------------------------
- _CLASSDEF(TTimerWindow)
- class TTimerWindow : public TWindow {
- // total test code!
- FARPROC lpProc;
- TestTimer *timer1,
- *timer2,
- *timer3;
- public:
- TTimerWindow(PTWindowsObject AParent, LPSTR ATitle);
-
- virtual void SetupWindow();
- virtual void Paint(HDC DC, PAINTSTRUCT& PS);
- virtual void ShutDownWindow();
- };
-
-
-
- //--------------------------------------------------------------------------
- //
- // TTimerWindow :: CONSTRUCTOR
- //
- //--------------------------------------------------------------------------
- TTimerWindow::TTimerWindow(PTWindowsObject AParent, LPSTR ATitle)
- : TWindow(AParent, ATitle)
- {
- // AssignMenu("COMMANDS");
- Attr.W = 400;
- Attr.H = 200;
-
- timer1 = timer2 = timer3 = NULL;
- }
-
-
- //--------------------------------------------------------------------------
- //
- // TTimerWindow :: Paint
- //
- //--------------------------------------------------------------------------
- void TTimerWindow::Paint(HDC DC, PAINTSTRUCT&)
- {
- timer1->draw(DC);
- timer2->draw(DC);
- timer3->draw(DC);
- }
-
-
-
- //--------------------------------------------------------------------------
- //
- // TTimerWindow :: SetupWindow
- //
- //--------------------------------------------------------------------------
- void TTimerWindow::SetupWindow()
- {
- TWindow::SetupWindow();
- RECT rLoc;
-
- rLoc.left = rLoc.top = 0;
- rLoc.right = 100, rLoc.bottom = 20;
-
- timer1 = new TestTimer(HWindow, rLoc, 500);
- rLoc.top += 20, rLoc.bottom +=20;
- timer2 = new TestTimer(HWindow, rLoc, 1000);
- rLoc.top += 20, rLoc.bottom +=20;
- timer3 = new TestTimer(HWindow, rLoc, 750);
- }
-
-
-
- //--------------------------------------------------------------------------
- //
- // TTimerWindow :: ShutDownWindow
- //
- //--------------------------------------------------------------------------
- void TTimerWindow::ShutDownWindow()
- {
- if(timer1) delete timer1;
- if(timer2) delete timer2;
- if(timer3) delete timer3;
- TWindow::ShutDownWindow();
- }
-
-
-
- //-------------------------------------------------------------------
- //
- // OWL Stuff to setup the application
- //
- //-------------------------------------------------------------------
- class TTimerApp : public TApplication {
- public:
- TTimerApp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow)
- {};
- virtual void InitMainWindow();
- };
-
- void TTimerApp::InitMainWindow()
- {
- MainWindow = new TTimerWindow(NULL, Name);
- }
-
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- TTimerApp MyApp("Object Callback Sample", hInstance, hPrevInstance,
- lpCmdLine, nCmdShow);
- MyApp.Run();
- return MyApp.Status;
- }
-
-
-